package com.gitee.zycra.future.job.client.executor;

import com.gitee.zycra.future.job.client.container.SystemInfoContainer;
import oshi.SystemInfo;
import oshi.hardware.GlobalMemory;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author zycra
 */
public final class MemoryPercentExecutor implements Runnable {

    private static final GlobalMemory MEMORY = new SystemInfo().getHardware().getMemory();

    @Override
    public void run() {
        BigDecimal total = BigDecimal.valueOf(MEMORY.getTotal());
        BigDecimal acaliable = BigDecimal.valueOf(MEMORY.getAvailable());
        SystemInfoContainer.MEMORY_USED_RATIO.set(total.subtract(acaliable).multiply(SystemInfoContainer.HUNDRED)
                .divide(total, RoundingMode.HALF_UP).intValue());
    }
}
